<template>
  <a-card>
    {{dashboardState.expand}}
    <div id="main3" style="height: 400px;width: 100%"></div>
  </a-card>
</template>
<script setup lang="ts">
const dashboardState = useStore.dashboardState()
import * as echarts from 'echarts';
let myChart = null
let base = +new Date(1968, 9, 3);
let oneDay = 24 * 3600 * 1000;
let date = [];
let data = [Math.random() * 300];
for (let i = 1; i < 20000; i++) {
  var now = new Date((base += oneDay));
  date.push([now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'));
  data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]));
}

const option = {
  tooltip: {
    trigger: 'axis',
    position: function (pt) {
      return [pt[0], '10%'];
    }
  },
  title: {
    left: 'center',
    text: '平台访问情况'
  },
  toolbox: {
    feature: {
      dataZoom: {
        yAxisIndex: 'none'
      },
      restore: {},
      saveAsImage: {}
    }
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: date
  },
  yAxis: {
    type: 'value',
    boundaryGap: [0, '100%']
  },
  dataZoom: [
    {
      type: 'inside',
      start: 0,
      end: 10
    },
    {
      start: 0,
      end: 10
    }
  ],
  series: [
    {
      name: 'Fake Data',
      type: 'line',
      symbol: 'none',
      sampling: 'lttb',
      itemStyle: {
        color: 'rgb(255, 70, 131)'
      },
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          {
            offset: 0,
            color: 'rgb(255, 158, 68)'
          },
          {
            offset: 1,
            color: 'rgb(255, 70, 131)'
          }
        ])
      },
      data: data
    }
  ]
};
const handleLoadChart = ()=>{
  nextTick(()=> {
    // 基于准备好的dom，初始化echarts实例
    myChart = echarts.init(document.getElementById('main3'));
    myChart.setOption(option)
    window.addEventListener('resize', function() {
      myChart.resize();
    });
  })
}

watch(()=>dashboardState.expand,(nval)=>{
  myChart.resize();
})

onMounted(()=>{
  handleLoadChart()
})
</script>
<style scoped lang="scss"></style>